home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / AppleTalk ToolKit / NBP / NBPRegisterName.c < prev   
Encoding:
C/C++ Source or Header  |  1995-02-07  |  5.1 KB  |  174 lines  |  [TEXT/MPS ]

  1. /*******************************************************************\
  2. *    file:         NBPRegisterName.c                                    *
  3. *    version:    1.06ß                                                 *
  4. *                                                                     *
  5. *    Register this node under the name defined in the chooser's         *
  6. *    name resource.                                                    *
  7. * -----------------------------------------------------------------    *
  8. * By:    Donald Koscheka, Greg Kimberly                                *
  9. * Date:    21-Sept-87                                                    *
  10. * ©    Copyright 1987, Apple Computer, Inc.                            *
  11. *    All Rights Reserved                                                *
  12. *                                                                    *
  13. * -----------------------------------------------------------------    *
  14. *                        Modification History                        *
  15. * -----------------------------------------------------------------    *
  16. *  Date           | By    |                     Description                    *
  17. * -----------------------------------------------------------------    *
  18. * 9/21/87    | GK    | file created                                    *
  19. * 10/6/87    | DK    | added parameter passing for name and type        *
  20. *  5-Nov-87    | DK    | added return result                            *
  21. *  8-Dec-87    | DK    | added verify flag to input parameter list        *
  22. * 21-Dec-87    | DK    | added "empty" name support                    *
  23. * 14-Jan-87    | DK    | modified to reflect decoupling of NBP & ATP    *
  24. *            | DK    | allows you to register only once                 *
  25. *            |        | (temporary patch for bug fix)                    *
  26. * -----------------------------------------------------------------    *
  27. \*******************************************************************/
  28.  
  29.  
  30. /*******************************************************************\
  31.                             Build Sequence
  32.     
  33. C -q2 -g -o "{hpo}"NBPRegisterName.c.o "{nbp}"NBPRegisterName.c
  34.     link  -sn Main=NBPRegisterName -sn STDIO=NBPRegisterName ∂
  35.          -sn INTENV=NBPRegisterName -rt XCMD=305 ∂
  36.          -m NBPREGISTERNAME ∂
  37.          "{hpo}"NBPRegisterName.c.o  "{hpo}"atalkxcmd.c.o "{hpo}"xcmdutils.c.o ∂
  38.          "{CLibraries}"CInterface.o ∂
  39.          "{Libraries}"Interface.o ∂
  40.          -o "{hp}"HyperPeople
  41.  
  42. \*******************************************************************/
  43.  
  44. #include <Types.h>
  45. #include <Memory.h>
  46. #include <Resources.h>
  47. #include <OSUtils.h>
  48. #include <appleTalk.h>
  49. #include <HyperXCmd.h>
  50. #include <atalkXCMD.h>
  51. #include <XCMDUtils.h>
  52.  
  53.  
  54. pascal void NBPRegisterName(paramPtr)
  55.     XCmdBlockPtr    paramPtr;
  56. /**********************************
  57. * Register this entity on the network
  58. * using the name and type specified.
  59. *
  60. *    params[0]    char    *theName
  61. *    params[1]    char    *theType
  62. *    params[2]    short    count
  63. *    params[3]    short    interval
  64. *    params[4]    short    verifyFlag
  65. * -----------------------------------
  66. *
  67. * defaults are: name    = (from chooser)
  68. *                type    = 'HyperPeople'
  69. *                count    = 2
  70. *                interval= 8
  71. *                verify    = false;
  72. *
  73. * NOTE: will not register if a socket
  74. * is not open on this node!
  75. **********************************/
  76. {
  77.     NBPBlock     *nbp;
  78.     char        theName[32], theType[32], temp[32], str[32];
  79.     Handle         myType    = nil;
  80.     Handle        myName    = nil;
  81.     Handle        saveName;
  82.     Handle         DataHandle;
  83.     short        count, interval, verify;
  84.     short        result = DEFAULT_ERROR;
  85.     long        len;
  86.     long        addrData;
  87.     AddrBlock    *addr;
  88.     
  89.     nbp = (NBPBlock *)RetrieveHandle( paramPtr, GLOBALNBPDATA );
  90.     
  91.     if( !nbp || nbp->Registered ){
  92.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  93.         return;
  94.     }
  95.     
  96.     /*** Before we can register, we need to get the internet address ***/
  97.     addr          = &(nbp->NTEntry.nt.nteAddress);
  98.     addrData      = RetrieveHandle( paramPtr, GLOBALSKTDATA );
  99.  
  100.     addr->aSocket= (unsigned char)    (0x000000FF & addrData);
  101.     addr->aNet     = (unsigned char)    (0x0000FF00 & addrData) >> 0x08;
  102.     addr->aNode  = (short)            (0xFFFF0000 & addrData) >> 0x10;
  103.  
  104.     if( (paramPtr->params[0] == nil) || !(**(paramPtr->params[0])) ){    
  105.         if( myName = GetResource('STR ', EntityNameStr ) ){
  106.             pStrCopy( *myName, theName );
  107.         }
  108.         else{
  109.             paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  110.             return;
  111.         }
  112.     }
  113.     else{
  114.         len = GetHandleSize( paramPtr->params[0] );
  115.         BlockMove( *(paramPtr->params[0]), theName, len );
  116.         c2pstr( theName );
  117.     }
  118.         
  119.     /*** save the registered name off in a global variable ***/
  120.     saveName = GetResource( 'STR ', myEntityNameStr     );
  121.     if( saveName ){
  122.         HLock( saveName );
  123.         DataHandle = PasToZero( paramPtr, theName );
  124.         SetGlobal( paramPtr, *saveName, DataHandle );    
  125.         DisposHandle( DataHandle );
  126.         HUnlock( saveName );
  127.     }
  128.     
  129.     if( paramPtr->params[1] == nil || !(**(paramPtr->params[1])) ){
  130.         if( myType = GetResource('STR ', EntityTypeStr ) ){
  131.             pStrCopy( *myType, theType );
  132.         }
  133.         else{
  134.             paramPtr->returnValue = ErrorReturn(  DEFAULT_ERROR );
  135.             return;
  136.         }
  137.     }
  138.     else{
  139.         len = GetHandleSize( paramPtr->params[1] );
  140.         BlockMove( *(paramPtr->params[1]), theType, len );
  141.         c2pstr( theType );
  142.     }
  143.  
  144.     if( paramPtr->params[2] != nil ){
  145.         len = GetHandleSize( paramPtr->params[2] );    
  146.         BlockMove( *(paramPtr->params[2]), temp, len );
  147.         c2pstr( temp );
  148.         count = (short)StrToNum( paramPtr, temp );
  149.     }
  150.     else
  151.         count = 2;    
  152.     
  153.     if( paramPtr->params[3] != nil ){    
  154.         len = GetHandleSize( paramPtr->params[3] );    
  155.         BlockMove( (*paramPtr->params[3]), temp, len );
  156.         c2pstr( temp );
  157.         interval = (short)StrToNum( paramPtr, temp );
  158.     }
  159.     else
  160.         interval = 8;
  161.     
  162.     verify = false;
  163.     MakeAnswer( true, str );
  164.         
  165.     if( paramPtr->params[4] != nil )
  166.         if( (strCMP( str, (*paramPtr->params[4]) )) == 0 ) 
  167.             verify = true;
  168.         
  169.     result = NodeRegister( nbp, theName, theType, count, interval, verify, addr );
  170.     
  171.     paramPtr->returnValue = ErrorReturn( result );
  172. }
  173.  
  174.